package com.mingtu.jgspatrol.activity;

import static com.mingtu.common.utils.MyUtills.getBounds;
import static com.mingtu.jgspatrol.utils.MyConstant.MAP_INDEX;
import static com.mingtu.jgspatrol.utils.MyConstant.MAX_ZOOM;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.os.Bundle;
import android.util.Pair;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;

import com.alibaba.fastjson.JSON;
import com.amap.api.location.DPoint;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.Polygon;
import com.amap.api.maps.model.PolygonOptions;
import com.amap.api.maps.model.Polyline;
import com.amap.api.maps.model.PolylineOptions;
import com.amap.api.maps.model.TileOverlay;
import com.amap.api.maps.model.TileOverlayOptions;
import com.amap.api.maps.utils.SpatialRelationUtil;
import com.amap.api.maps.utils.overlay.MovingPointOverlay;
import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.SPStaticUtils;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.gyf.immersionbar.ImmersionBar;
import com.hjq.gson.factory.GsonFactory;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.mingtu.common.base.BaseApplication;
import com.mingtu.common.base.BaseBindingActivity;
import com.mingtu.common.bean.ResAreaBean;
import com.mingtu.common.bean.UserInfoBean;
import com.mingtu.common.callback.ResultCallback;
import com.mingtu.common.callback.StringDialogCallback;
import com.mingtu.common.room.TrackEvent;
import com.mingtu.common.room.TrackEventDao;
import com.mingtu.common.room.TrackHistoryEvent;
import com.mingtu.common.room.TrackHistoryEventDao;
import com.mingtu.common.utils.Constant;
import com.mingtu.common.utils.GZip.GZipUtil;
import com.mingtu.common.utils.MyLogUtil;
import com.mingtu.common.utils.MyUtills;
import com.mingtu.common.utils.PlayMusicUtils;
import com.mingtu.common.utils.SPTools;
import com.mingtu.common.utils.TileUtils;
import com.mingtu.jgspatrol.R;
import com.mingtu.jgspatrol.callback.MyStringDialogCallback;
import com.mingtu.jgspatrol.databinding.ActivityTrackEndBinding;
import com.mingtu.jgspatrol.share.BottomPopupShare;
import com.mingtu.jgspatrol.utils.MyConstant;
import com.mob.MobSDK;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;

import cn.sharesdk.onekeyshare.OnekeyShare;
import cn.sharesdk.wechat.favorite.WechatFavorite;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;
import okhttp3.OkHttpClient;

public class TrackEndActivity extends BaseBindingActivity<ActivityTrackEndBinding> implements AMap.OnMapScreenShotListener {
    private AMap aMap;
    private Marker startMarker;
    private Marker endMarker;
    private Polyline mapPolyline;
    private String startTime;
    private String endTime;
    private long duration;
    private String distance;
    private String taskId;
    private String favId;
    private List<HashMap<String, Object>> uploadLocationList;
    private List<HashMap<String, Object>> uploadList = new ArrayList<>();
    private List<String> areaList; //暂时没有用
    private List<LatLng> myPointList;

    private List<Marker> markers = new CopyOnWriteArrayList<>();
    private List<Polyline> polylines = new CopyOnWriteArrayList<>();
    private List<Polyline> movePolylines = new CopyOnWriteArrayList<>();
    private String trackId;
    private List<LatLng> pausePoints = new ArrayList<>(); //存储暂停的点
    private List<LatLng> moveTrackList = new ArrayList<>();
    private List<LatLng> validList = new ArrayList<>(); //有效的巡护点
    private MovingPointOverlay smoothMarker;
    private Marker moveMarker;
    private int moveTime = 6;

    private TileOverlayOptions tileOverlayOptions;
    private TileOverlay tileOverlay;
    private BasePopupView popupView;
    private Bitmap shotBitmap;
    private double validDistance;
    private List<Polygon> trackPolygonList = new ArrayList<>();
    private List<Polyline> polylineList = new ArrayList<>();
    private TrackEventDao trackEventDao;
    private OkHttpClient.Builder builder;
    private TrackHistoryEventDao trackHistoryEventDao;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_track_end;
    }

    @Override
    protected void initView() {
        setModuleTitle("巡护结束");
        ImmersionBar immersionBar = ImmersionBar.with(this);
        immersionBar.statusBarDarkFont(true);
        immersionBar.init();
        showTopRightImg(R.mipmap.icon_share_black);
    }

    @Override
    protected void initData() {
        trackEventDao = BaseApplication.getBaseApplication().getTrackEventDao();
        trackHistoryEventDao = BaseApplication.getBaseApplication().getTrackHistoryEventDao();
        PlayMusicUtils.playSound(this, "endTrack.mp3");
        try {

            uploadLocationList = (ArrayList<HashMap<String, Object>>) getIntent().getSerializableExtra("uploadLocation");//存放用户上报的经纬度信息

            duration = getIntent().getLongExtra("duration", 0);
            distance = getIntent().getStringExtra("distance");
            startTime = getIntent().getStringExtra("startTime");
            endTime = getIntent().getStringExtra("endTime");

            binding.tvMileage.setText(distance);
            binding.tvElapsedTime.setText(MyUtills.formatSeconds3(duration));
            binding.tvStartTime.setText("开始时间：" + MyUtills.stampToDateTime(startTime));
            binding.tvEndTime.setText("结束时间：" + MyUtills.stampToDateTime(endTime));

            String geoFenceFlag = SPStaticUtils.getString(SPTools.GeoFenceFlag);
            if (!StringUtils.isEmpty(geoFenceFlag)) {
                String str = "";
                if (geoFenceFlag.equals(Constant.AUTO_END_TRACK_TYPE_ONE)) {
                    str = "巡护时间超出" + MyConstant.TRACK_AUTO_END_TIME / 3600 + "小时，已经自动结束巡护！";
                } else if (geoFenceFlag.equals(Constant.AUTO_END_TRACK_TYPE_TWO)) {
                    str = "巡护超出地理围栏，已经自动结束巡护！";
                }
                showAlertDialog(str);
            }

            //获取用户信息
            getUserInfo();
            //上报点的逻辑
            uploadPointsEvent();
            //需要在上报点逻辑之后
            //轨迹相关逻辑
            dealTrackHistoryData(new ResultCallback() {
                @Override
                public void result(Object object) {
                    JSONArray array = (JSONArray) object;
                    if (array != null) {
                        uploadTask(array);
                        smoothMoveTrack();
                    }
                }
            });


        } catch (Exception e) {
            e.printStackTrace();
        }


        binding.ivCollect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    //收藏轨迹
                    collectTrack();
                } else {
                    //取消收藏轨迹
                    cancleCollectTrack();
                }
            }
        });

    }

    @Override
    protected void initMap(Bundle savedInstanceState) {
        super.initMap(savedInstanceState);
        binding.mapView.onCreate(savedInstanceState);
        aMap = binding.mapView.getMap();
        //地图模式可选类型：MAP_TYPE_NORMAL,MAP_TYPE_SATELLITE,MAP_TYPE_NIGHT
        aMap.setMapType(AMap.MAP_TYPE_SATELLITE);// 矢量地图模式
        aMap.getUiSettings().setMyLocationButtonEnabled(false);// 设置默认定位按钮是否显示
        aMap.getUiSettings().setZoomControlsEnabled(false);
        aMap.setMaxZoomLevel(MAX_ZOOM);
        aMap.setMapTextZIndex(1);
        aMap.moveCamera(CameraUpdateFactory.zoomTo(Constant.MAP_ZOOM));
        //自定义瓦片
        tileOverlayOptions = TileUtils.getTileOverlayOptions();
        tileOverlay = aMap.addTileOverlay(tileOverlayOptions);
    }

    @Override
    protected void getData() {
//        getAreaData();
    }

    @Override
    protected void onResume() {
        super.onResume();
        binding.mapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        binding.mapView.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (smoothMarker != null) {
            smoothMarker.stopMove();
            smoothMarker.setMoveListener(null);
            smoothMarker.destroy();
        }

        if (builder != null) {
            OkGo.getInstance().cancelTag(builder.build(), this);
        }

        //销毁地图对象
        if (aMap != null) {
            binding.mapView.onDestroy();
            aMap.clear();
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState)，
        //保存地图当前的状态
        binding.mapView.onSaveInstanceState(outState);
    }


    @Override
    protected void onClickedTopLeftButtton(View view) {
        setResult(Constant.RESULT_CODE_ONE);
        super.onClickedTopLeftButtton(view);
    }

    @Override
    protected void onKeyDownEvnet() {
        setResult(Constant.RESULT_CODE_ONE);
        super.onKeyDownEvnet();
    }

    @Override
    protected void onClickTitlebarRight(View view) {
        super.onClickTitlebarRight(view);
        aMap.getMapScreenShot(this);
        //分享截屏
        BottomPopupShare bottomPopup = new BottomPopupShare(this);
        bottomPopup.setOnItemClickListener(new BottomPopupShare.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                popupView.dismiss();
//                Bitmap bitmap = ScreenUtils.screenShot(TrackEndActivity.this, true);
//                UMImage thumb = new UMImage(TrackEndActivity.this, bitmap);
//                UMImage image = new UMImage(TrackEndActivity.this, bitmap);//资源文件
//                image.setThumb(thumb);
//                image.compressStyle = UMImage.CompressStyle.QUALITY;//质量压缩，适合长图的分享
//                ShareAction shareAction = new ShareAction(TrackEndActivity.this);
//                if (position == 0) {
//                    //好友
//                    //指定分享的平台，如果为空，还是会调用九宫格的平台列表界面
//                    shareAction.setPlatform(SHARE_MEDIA.WEIXIN);
//
//                } else if (position == 1) {
//                    //朋友圈
//                    shareAction.setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE);
//                } else if (position == 2) {
//                    //收藏
//                    shareAction.setPlatform(SHARE_MEDIA.WEIXIN_FAVORITE);
//                }
//                shareAction.withText("再接再厉，继续加油哦！");
//                shareAction.withMedia(image);
//                shareAction.share();

                final OnekeyShare oks = new OnekeyShare();
                // titleUrl是标题的网络链接，仅在Linked-in,QQ和QQ空间使用
                oks.setTitleUrl("https://www.mingtukeji.com");
                // text是分享文本，所有平台都需要这个字段
                oks.setText("巡护结束，继续加油哦！");
                //分享网络图片，新浪微博分享网络图片需要通过审核后申请高级写入接口，否则请注释掉测试新浪微博
                //oks.setImageUrl("http://f1.sharesdk.cn/imgs/2014/02/26/owWpLZo_638x960.jpg");
                // url仅在微信（包括好友和朋友圈）中使用
                oks.setImageData(shotBitmap);
                if (position == 0) {
                    //好友
                    //指定分享的平台，如果为空，还是会调用九宫格的平台列表界面
                    // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间使用
                    oks.setTitle("巡护任务");
                    oks.setPlatform(Wechat.NAME);
                    oks.show(MobSDK.getContext());
                } else if (position == 1) {
                    //朋友圈
                    oks.setPlatform(WechatMoments.NAME);
                    oks.show(MobSDK.getContext());
                } else if (position == 2) {
                    //收藏
                    oks.setPlatform(WechatFavorite.NAME);
                    oks.show(MobSDK.getContext());
                }


            }
        });
        popupView = new XPopup.Builder(this)
                .moveUpToKeyboard(false) //如果不加这个，评论弹窗会移动到软键盘上面
                .enableDrag(true)
                .isDarkTheme(true)
                .navigationBarColor(getResources().getColor(R.color.black))
                .isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
//                        .isThreeDrag(true) //是否开启三阶拖拽，如果设置enableDrag(false)则无效
                .asCustom(bottomPopup)
                .show();

    }

    @Override
    public void onMapScreenShot(Bitmap bitmap) {
        shotBitmap = getMapAndViewScreenShot(bitmap, binding.container, binding.mapView, binding.content, binding.tvName);
        int size = shotBitmap.getByteCount();
    }

    @Override
    public void onMapScreenShot(Bitmap bitmap, int i) {

    }

    /**
     * 平滑移动巡护轨迹的事件
     */
    private void smoothMoveTrack() {
        // 取轨迹点的第一个点 作为 平滑移动的启动
        LatLng drivePoint = myPointList.get(0);
        Pair<Integer, LatLng> pair = SpatialRelationUtil.calShortestDistancePoint(myPointList, drivePoint);
        myPointList.set(pair.first, drivePoint);
        List<LatLng> subList = myPointList.subList(pair.first, myPointList.size());

        if (smoothMarker == null) {
            // 设置 平滑移动的 图标
            ArrayList<BitmapDescriptor> giflist = new ArrayList<BitmapDescriptor>();
            giflist.add(BitmapDescriptorFactory.fromResource(com.mingtu.home.R.mipmap.icon_people01));
//                                        giflist.add(BitmapDescriptorFactory.fromResource(R.mipmap.icon_people02));
            giflist.add(BitmapDescriptorFactory.fromResource(com.mingtu.home.R.mipmap.icon_people03));
//                                        giflist.add(BitmapDescriptorFactory.fromResource(R.mipmap.icon_people04));

            moveMarker = aMap.addMarker(new MarkerOptions()
                    .zIndex(MAP_INDEX)
                    .anchor(0.5f, 0.5f)
                    .icons(giflist));
            smoothMarker = new MovingPointOverlay(aMap, moveMarker);
        }

        smoothMarker.setPoints(subList); // 设置轨迹点
        smoothMarker.setTotalDuration(moveTime);// 设置平滑移动的总时间  单位  秒
        smoothMarker.setMoveListener(new MovingPointOverlay.MoveListener() {
            int num = 0;
            int[] doublePointIndex = {0, 1};

            @Override
            public void move(final double distance) {
                num += 1;
                int index = smoothMarker.getIndex();
                if (num == 1) {
                    doublePointIndex[0] = 0;
                    return;
                } else {
                    doublePointIndex[1] = index;
                }
                List<LatLng> sub = myPointList.subList(doublePointIndex[0], doublePointIndex[1]);
                for (LatLng latLng : sub) {
                    moveTrackList.add(latLng);
                    if (pausePoints.contains(latLng)) {
                        moveTrackList.clear();
                        moveTrackList.add(latLng);
                    } else {
                        if (moveTrackList.size() >= 2) { //两段成一条线，画线完成后把之前的坐标数组清除，并把当前坐标添加进去
                            Polyline mapPolyline = aMap.addPolyline(new PolylineOptions()
                                    .addAll(moveTrackList)
                                    .zIndex(MAP_INDEX)
                                    .width(Constant.POLYLINE_WIDTH)
                                    .color(getResources().getColor(com.mingtu.home.R.color.colorPrimary)));
                            movePolylines.add(mapPolyline);
                            moveTrackList.clear();
                            moveTrackList.add(latLng); //清除之前的数组之后，添加当前的坐标

                        }

                    }

                    aMap.animateCamera(CameraUpdateFactory.newLatLng(latLng)); //此处animateCamera   moveCamera两个地方同时使用一个的话，效果不好
                    aMap.moveCamera(CameraUpdateFactory.changeTilt(35));

                }
                doublePointIndex[0] = index; //将上段的终点坐标作为起点
                moveTrackList.clear();
                if (sub.size() > 0) { //将分割后的段落的最后一个坐标添加到下个分割段落
                    moveTrackList.add(sub.get(sub.size() - 1));
                } else {
                    moveTrackList.add(sub.get(0));
                }

                if (distance == 0) {
                    if (index < myPointList.size() - 1) {
                        if (myPointList.size() > 0) {
                            List<LatLng> endList = myPointList.subList(index, myPointList.size());
                            moveTrackList.addAll(endList);
                            Polyline mapPolyline = aMap.addPolyline(new PolylineOptions()
                                    .addAll(moveTrackList)
                                    .zIndex(MAP_INDEX)
                                    .width(Constant.POLYLINE_WIDTH)
                                    .color(getResources().getColor(com.mingtu.home.R.color.colorPrimary)));
                            movePolylines.add(mapPolyline);
                        }
                    }

                    smoothMarker.stopMove();
                    //添加结束Marker
                    MarkerOptions endMarkerOptions = new MarkerOptions()
                            .position(myPointList.get(myPointList.size() - 1))
                            .zIndex(MAP_INDEX)
                            .icon(BitmapDescriptorFactory.fromResource(com.mingtu.home.R.mipmap.icon_end));
                    Marker endMarker = aMap.addMarker(endMarkerOptions);
                    markers.add(endMarker);

                    moveMarker.remove();

                    aMap.animateCamera(CameraUpdateFactory.changeTilt(0));
                    aMap.animateCamera(CameraUpdateFactory.newLatLngBounds(getBounds(myPointList), 200));
                }
            }
        });
        // 开始移动
        smoothMarker.startSmoothMove();
        //添加开始Marker
        MarkerOptions startMarkerOptions = new MarkerOptions()
                .position(myPointList.get(0))
                .zIndex(MAP_INDEX)
                .icon(BitmapDescriptorFactory.fromResource(com.mingtu.home.R.mipmap.icon_start));
        Marker startMarker = aMap.addMarker(startMarkerOptions);
        markers.add(startMarker);
    }

    /**
     * 处理巡护的数据
     *
     * @param resultCallback
     */
    private void dealTrackHistoryData(ResultCallback resultCallback) {

        List<TrackHistoryEvent> trackHistoryEvents = trackHistoryEventDao.getAll();
//            String trackHistory = "{\"historyArray\":[{\"history\": [{\"longitude\":113.71345028704947,\"latitude\":34.5924181882019,\"locationTime\":\"1617235183000\",\"flagPoint\":false},{\"longitude\":113.71344822782171,\"latitude\":34.59245091312842,\"locationTime\":\"1617235185000\",\"flagPoint\":false},{\"longitude\":113.71344819839194,\"latitude\":34.592478788099534,\"locationTime\":\"1617235187000\",\"flagPoint\":false},{\"longitude\":113.71346857139724,\"latitude\":34.592516222483894,\"locationTime\":\"1617235190000\",\"flagPoint\":false},{\"longitude\":113.71350228621546,\"latitude\":34.592516682571485,\"locationTime\":\"1617235191000\",\"flagPoint\":false}]},\n" +
//                    "{\"history\":[{\"longitude\":113.71345028704947,\"latitude\":34.5924181882019,\"locationTime\":\"1617235183000\",\"pointflag\":true},{\"longitude\":113.71344822782171,\"latitude\":34.59245091312842,\"locationTime\":\"1617235185000\",\"pointflag\":false},{\"longitude\":113.71344819839194,\"latitude\":34.592478788099534,\"locationTime\":\"1617235187000\",\"pointflag\":false},{\"longitude\":113.71346857139724,\"latitude\":34.592516222483894,\"locationTime\":\"1617235190000\",\"pointflag\":false},{\"longitude\":113.71350228621546,\"latitude\":34.592516682571485,\"locationTime\":\"1617235191000\",\"pointflag\":false},{\"longitude\":113.7135389511772,\"latitude\":34.5925253293037,\"locationTime\":\"1617235193000\",\"pointflag\":false},{\"longitude\":113.71357150525277,\"latitude\":34.59253247561952,\"locationTime\":\"1617235194000\",\"pointflag\":false},{\"longitude\":113.7136110719399,\"latitude\":34.59253900696666,\"locationTime\":\"1617235195000\",\"pointflag\":false},{\"longitude\":113.71364775401912,\"latitude\":34.592540384394745,\"locationTime\":\"1617235196000\",\"pointflag\":false},{\"longitude\":113.71368558698862,\"latitude\":34.59253932807857,\"locationTime\":\"1617235197000\",\"pointflag\":false},{\"longitude\":113.71375196674464,\"latitude\":34.59253843413538,\"locationTime\":\"1617235199000\",\"pointflag\":false},{\"longitude\":113.71378650082714,\"latitude\":34.59253563128671,\"locationTime\":\"1617235200000\",\"pointflag\":false},{\"longitude\":113.71381906356407,\"latitude\":34.59252877987372,\"locationTime\":\"1617235201000\",\"pointflag\":false},{\"longitude\":113.71387841352302,\"latitude\":34.59252012253441,\"locationTime\":\"1617235203000\",\"pointflag\":false},{\"longitude\":113.71392004407994,\"latitude\":34.59250033438587,\"locationTime\":\"1617235205000\",\"pointflag\":false},{\"longitude\":113.71397075626307,\"latitude\":34.59248479633455,\"locationTime\":\"1617235207000\",\"pointflag\":false},{\"longitude\":113.71401302292173,\"latitude\":34.59247111176557,\"locationTime\":\"1617235209000\",\"pointflag\":false},{\"longitude\":113.71406410394239,\"latitude\":34.592455073928555,\"locationTime\":\"1617235211000\",\"pointflag\":false},{\"longitude\":113.71411916010983,\"latitude\":34.5924477522513,\"locationTime\":\"1617235213000\",\"pointflag\":false},{\"longitude\":113.71416561347145,\"latitude\":34.59244255749501,\"locationTime\":\"1617235215000\",\"pointflag\":false},{\"longitude\":113.71421404795011,\"latitude\":34.592434278447584,\"locationTime\":\"1617235217000\",\"pointflag\":false},{\"longitude\":113.71427029146429,\"latitude\":34.592438879243076,\"locationTime\":\"1617235219000\",\"pointflag\":false},{\"longitude\":113.71433418630865,\"latitude\":34.59244580349918,\"locationTime\":\"1617235221000\",\"pointflag\":false},{\"longitude\":113.71429203815816,\"latitude\":34.5924779629259,\"locationTime\":\"1617235226000\",\"pointflag\":false},{\"longitude\":113.71425968585886,\"latitude\":34.592525192630504,\"locationTime\":\"1617235228000\",\"pointflag\":false},{\"longitude\":113.71422837527716,\"latitude\":34.59254238338244,\"locationTime\":\"1617235229000\",\"pointflag\":false},{\"longitude\":113.7142003229623,\"latitude\":34.592560387957164,\"locationTime\":\"1617235230000\",\"pointflag\":false},{\"longitude\":113.7141573866341,\"latitude\":34.59258354484469,\"locationTime\":\"1617235232000\",\"pointflag\":false},{\"longitude\":113.71413002930917,\"latitude\":34.59261478407785,\"locationTime\":\"1617235234000\",\"pointflag\":false},{\"longitude\":113.7141005342155,\"latitude\":34.59257031419738,\"locationTime\":\"1617235249000\",\"pointflag\":false},{\"longitude\":113.71407970098406,\"latitude\":34.59253187805413,\"locationTime\":\"1617235251000\",\"pointflag\":false},{\"longitude\":113.71407728649282,\"latitude\":34.59249088216918,\"locationTime\":\"1617235253000\",\"pointflag\":false},{\"longitude\":113.71409097809266,\"latitude\":34.592464705213224,\"locationTime\":\"1617235254000\",\"pointflag\":false},{\"longitude\":113.71411779751554,\"latitude\":34.592434183113745,\"locationTime\":\"1617235255000\",\"pointflag\":false},{\"longitude\":113.71415471258055,\"latitude\":34.59241066004478,\"locationTime\":\"1617235256000\",\"pointflag\":false},{\"longitude\":113.71421023557699,\"latitude\":34.59238492456777,\"locationTime\":\"1617235257000\",\"pointflag\":false},{\"longitude\":113.71426286380421,\"latitude\":34.592340543913394,\"locationTime\":\"1617235258000\",\"pointflag\":false},{\"longitude\":113.71432424340064,\"latitude\":34.59232521181672,\"locationTime\":\"1617235259000\",\"pointflag\":false},{\"longitude\":113.71440323889613,\"latitude\":34.59233623097445,\"locationTime\":\"1617235260000\",\"pointflag\":false},{\"longitude\":113.71447082229783,\"latitude\":34.59233412844576,\"locationTime\":\"1617235261000\",\"pointflag\":false},{\"longitude\":113.71453746238458,\"latitude\":34.59232559959634,\"locationTime\":\"1617235262000\",\"pointflag\":false},{\"longitude\":113.7146032762389,\"latitude\":34.592304307717946,\"locationTime\":\"1617235263000\",\"pointflag\":false},{\"longitude\":113.71466702521334,\"latitude\":34.592289068438134,\"locationTime\":\"1617235264000\",\"pointflag\":false},{\"longitude\":113.71472899402153,\"latitude\":34.59228836752996,\"locationTime\":\"1617235265000\",\"pointflag\":false},{\"longitude\":113.71477843564018,\"latitude\":34.59229885913724,\"locationTime\":\"1617235266000\",\"pointflag\":false},{\"longitude\":113.71482499183749,\"latitude\":34.59233147241106,\"locationTime\":\"1617235267000\",\"pointflag\":false},{\"longitude\":113.71484369540394,\"latitude\":34.592367973965686,\"locationTime\":\"1617235268000\",\"pointflag\":false},{\"longitude\":113.7148503350558,\"latitude\":34.59241099834719,\"locationTime\":\"1617235269000\",\"pointflag\":false},{\"longitude\":113.71484934747463,\"latitude\":34.59247790308277,\"locationTime\":\"1617235270000\",\"pointflag\":false},{\"longitude\":113.71484933068801,\"latitude\":34.59255765076521,\"locationTime\":\"1617235271000\",\"pointflag\":false},{\"longitude\":113.71486609203585,\"latitude\":34.592656126697385,\"locationTime\":\"1617235272000\",\"pointflag\":false},{\"longitude\":113.71488050516983,\"latitude\":34.59273356632308,\"locationTime\":\"1617235273000\",\"pointflag\":false},{\"longitude\":113.71490465736325,\"latitude\":34.59279814066089,\"locationTime\":\"1617235274000\",\"pointflag\":false},{\"longitude\":113.71492707069719,\"latitude\":34.59285502427155,\"locationTime\":\"1617235275000\",\"pointflag\":false},{\"longitude\":113.71494772977097,\"latitude\":34.592906580182955,\"locationTime\":\"1617235276000\",\"pointflag\":false},{\"longitude\":113.71497034296348,\"latitude\":34.59295177395847,\"locationTime\":\"1617235277000\",\"pointflag\":false},{\"longitude\":113.71500762223975,\"latitude\":34.59299609960058,\"locationTime\":\"1617235278000\",\"pointflag\":false},{\"longitude\":113.71504518971174,\"latitude\":34.593019862864416,\"locationTime\":\"1617235279000\",\"pointflag\":false},{\"longitude\":113.71509733687729,\"latitude\":34.59302808371208,\"locationTime\":\"1617235280000\",\"pointflag\":false},{\"longitude\":113.71516429631444,\"latitude\":34.5930259320463,\"locationTime\":\"1617235281000\",\"pointflag\":false},{\"longitude\":113.71524376226927,\"latitude\":34.59301949044886,\"locationTime\":\"1617235282000\",\"pointflag\":false},{\"longitude\":113.71532316646099,\"latitude\":34.593016720905126,\"locationTime\":\"1617235283000\",\"pointflag\":false},{\"longitude\":113.71540011843207,\"latitude\":34.59301901939716,\"locationTime\":\"1617235284000\",\"pointflag\":false},{\"longitude\":113.7154672370499,\"latitude\":34.59302186926366,\"locationTime\":\"1617235285000\",\"pointflag\":false},{\"longitude\":113.71553151395622,\"latitude\":34.59302349158287,\"locationTime\":\"1617235286000\",\"pointflag\":false},{\"longitude\":113.71559787535126,\"latitude\":34.59301173983744,\"locationTime\":\"1617235287000\",\"pointflag\":false},{\"longitude\":113.71566940381425,\"latitude\":34.592990305469684,\"locationTime\":\"1617235288000\",\"pointflag\":false},{\"longitude\":113.71574713013626,\"latitude\":34.59296632497682,\"locationTime\":\"1617235289000\",\"pointflag\":false},{\"longitude\":113.71583122630986,\"latitude\":34.59294514388946,\"locationTime\":\"1617235290000\",\"pointflag\":false},{\"longitude\":113.71591974084247,\"latitude\":34.59292856118428,\"locationTime\":\"1617235291000\",\"pointflag\":false},{\"longitude\":113.71601120063804,\"latitude\":34.59291126293876,\"locationTime\":\"1617235292000\",\"pointflag\":false},{\"longitude\":113.71610786932885,\"latitude\":34.59289627842805,\"locationTime\":\"1617235293000\",\"pointflag\":false},{\"longitude\":113.71620730957099,\"latitude\":34.592876842496516,\"locationTime\":\"1617235294000\",\"pointflag\":false},{\"longitude\":113.71630704890289,\"latitude\":34.59285547660757,\"locationTime\":\"1617235295000\",\"pointflag\":false},{\"longitude\":113.71641103952629,\"latitude\":34.592834481328204,\"locationTime\":\"1617235296000\",\"pointflag\":false},{\"longitude\":113.71651748942435,\"latitude\":34.592814367351785,\"locationTime\":\"1617235297000\",\"pointflag\":false},{\"longitude\":113.71662926471555,\"latitude\":34.592795204195674,\"locationTime\":\"1617235298000\",\"pointflag\":false},{\"longitude\":113.7167447640364,\"latitude\":34.592779231533484,\"locationTime\":\"1617235299000\",\"pointflag\":false},{\"longitude\":113.71685585660299,\"latitude\":34.59275995470096,\"locationTime\":\"1617235300000\",\"pointflag\":false},{\"longitude\":113.71696390980603,\"latitude\":34.59273640151669,\"locationTime\":\"1617235301000\",\"pointflag\":false},{\"longitude\":113.71706746471938,\"latitude\":34.59270739021971,\"locationTime\":\"1617235302000\",\"pointflag\":false},{\"longitude\":113.71717069067302,\"latitude\":34.59267838233589,\"locationTime\":\"1617235303000\",\"pointflag\":false},{\"longitude\":113.71727917378595,\"latitude\":34.59265697415645,\"locationTime\":\"1617235304000\",\"pointflag\":false},{\"longitude\":113.71739112671312,\"latitude\":34.59264043867559,\"locationTime\":\"1617235305000\",\"pointflag\":false},{\"longitude\":113.71750675107388,\"latitude\":34.59262838383911,\"locationTime\":\"1617235306000\",\"pointflag\":false},{\"longitude\":113.71761673392439,\"latitude\":34.592613597762686,\"locationTime\":\"1617235307000\",\"pointflag\":false},{\"longitude\":113.7177154165567,\"latitude\":34.59259790344184,\"locationTime\":\"1617235308000\",\"pointflag\":false},{\"longitude\":113.71781376985763,\"latitude\":34.592586086337114,\"locationTime\":\"1617235309000\",\"pointflag\":false},{\"longitude\":113.71791775509709,\"latitude\":34.59257566583973,\"locationTime\":\"1617235310000\",\"pointflag\":false},{\"longitude\":113.71802562525586,\"latitude\":34.59255986684556,\"locationTime\":\"1617235311000\",\"pointflag\":false},{\"longitude\":113.71813596190641,\"latitude\":34.592538081477215,\"locationTime\":\"1617235312000\",\"pointflag\":false},{\"longitude\":113.7182471652044,\"latitude\":34.592512650062645,\"locationTime\":\"1617235313000\",\"pointflag\":false},{\"longitude\":113.7183616720467,\"latitude\":34.5924896506371,\"locationTime\":\"1617235314000\",\"pointflag\":false},{\"longitude\":113.71848044092289,\"latitude\":34.59246847720392,\"locationTime\":\"1617235315000\",\"pointflag\":false},{\"longitude\":113.71859800677612,\"latitude\":34.592449863063614,\"locationTime\":\"1617235316000\",\"pointflag\":false},{\"longitude\":113.71870982542998,\"latitude\":34.592432442263046,\"locationTime\":\"1617235317000\",\"pointflag\":false},{\"longitude\":113.71881672349427,\"latitude\":34.592416052885945,\"locationTime\":\"1617235318000\",\"pointflag\":false},{\"longitude\":113.71892451246653,\"latitude\":34.592401194174116,\"locationTime\":\"1617235319000\",\"pointflag\":false},{\"longitude\":113.71903724788383,\"latitude\":34.592388539171544,\"locationTime\":\"1617235320000\",\"pointflag\":false},{\"longitude\":113.71915331404983,\"latitude\":34.592375049864124,\"locationTime\":\"1617235321000\",\"pointflag\":false},{\"longitude\":113.71926932147699,\"latitude\":34.59236202159194,\"locationTime\":\"1617235322000\",\"pointflag\":false},{\"longitude\":113.71937836313097,\"latitude\":34.5923480110662,\"locationTime\":\"1617235323000\",\"pointflag\":false},{\"longitude\":113.7194798720153,\"latitude\":34.59233452702768,\"locationTime\":\"1617235324000\",\"pointflag\":false},{\"longitude\":113.7195748430825,\"latitude\":34.59232289720163,\"locationTime\":\"1617235325000\",\"pointflag\":false},{\"longitude\":113.71966522375119,\"latitude\":34.59231037861903,\"locationTime\":\"1617235326000\",\"pointflag\":false},{\"longitude\":113.7197527778063,\"latitude\":34.59229366346314,\"locationTime\":\"1617235327000\",\"pointflag\":false},{\"longitude\":113.71983739944912,\"latitude\":34.59227350363277,\"locationTime\":\"1617235328000\",\"pointflag\":false},{\"longitude\":113.71991668131618,\"latitude\":34.59225472613756,\"locationTime\":\"1617235329000\",\"pointflag\":false},{\"longitude\":113.71999754607943,\"latitude\":34.59223492780148,\"locationTime\":\"1617235330000\",\"pointflag\":false},{\"longitude\":113.72008405930609,\"latitude\":34.59221798767614,\"locationTime\":\"1617235331000\",\"pointflag\":false},{\"longitude\":113.72017710409668,\"latitude\":34.59220219686754,\"locationTime\":\"1617235332000\",\"pointflag\":false},{\"longitude\":113.72027602413326,\"latitude\":34.592183275215646,\"locationTime\":\"1617235333000\",\"pointflag\":false},{\"longitude\":113.72038183893126,\"latitude\":34.592160992289216,\"locationTime\":\"1617235334000\",\"pointflag\":false},{\"longitude\":113.72048985610705,\"latitude\":34.5921388025555,\"locationTime\":\"1617235335000\",\"pointflag\":false},{\"longitude\":113.72059585900425,\"latitude\":34.59211821387453,\"locationTime\":\"1617235336000\",\"pointflag\":false},{\"longitude\":113.72069726435986,\"latitude\":34.592101309399794,\"locationTime\":\"1617235337000\",\"pointflag\":false},{\"longitude\":113.72079221953847,\"latitude\":34.592086985553536,\"locationTime\":\"1617235338000\",\"pointflag\":false},{\"longitude\":113.72088156086953,\"latitude\":34.59207301321506,\"locationTime\":\"1617235339000\",\"pointflag\":false},{\"longitude\":113.72096962820743,\"latitude\":34.59205818289216,\"locationTime\":\"1617235340000\",\"pointflag\":false},{\"longitude\":113.72106126537487,\"latitude\":34.59203982426836,\"locationTime\":\"1617235341000\",\"pointflag\":false},{\"longitude\":113.72115010242881,\"latitude\":34.592023597623474,\"locationTime\":\"1617235342000\",\"pointflag\":false},{\"longitude\":113.7212340875149,\"latitude\":34.59200992563485,\"locationTime\":\"1617235343000\",\"pointflag\":false},{\"longitude\":113.72131563134558,\"latitude\":34.59199838983174,\"locationTime\":\"1617235344000\",\"pointflag\":false},{\"longitude\":113.72139569635958,\"latitude\":34.591983981866676,\"locationTime\":\"1617235345000\",\"pointflag\":false},{\"longitude\":113.72147084481388,\"latitude\":34.59197094434079,\"locationTime\":\"1617235346000\",\"pointflag\":false},{\"longitude\":113.72154107996444,\"latitude\":34.59195881603086,\"locationTime\":\"1617235347000\",\"pointflag\":false},{\"longitude\":113.72160552514423,\"latitude\":34.59194932273087,\"locationTime\":\"1617235348000\",\"pointflag\":false},{\"longitude\":113.72166775483448,\"latitude\":34.59193981291012,\"locationTime\":\"1617235349000\",\"pointflag\":false},{\"longitude\":113.72172111081001,\"latitude\":34.59193508973214,\"locationTime\":\"1617235350000\",\"pointflag\":false},{\"longitude\":113.72176471576874,\"latitude\":34.59193376228322,\"locationTime\":\"1617235351000\",\"pointflag\":false},{\"longitude\":113.72180405043396,\"latitude\":34.59194498851216,\"locationTime\":\"1617235353000\",\"pointflag\":false},{\"longitude\":113.72183917498911,\"latitude\":34.59194828256948,\"locationTime\":\"1617235355000\",\"pointflag\":false},{\"longitude\":113.7218828053858,\"latitude\":34.59194116780611,\"locationTime\":\"1617235356000\",\"pointflag\":false},{\"longitude\":113.72194003587639,\"latitude\":34.59192982432839,\"locationTime\":\"1617235357000\",\"pointflag\":false},{\"longitude\":113.72201270536115,\"latitude\":34.591920232905736,\"locationTime\":\"1617235358000\",\"pointflag\":false},{\"longitude\":113.72209561897593,\"latitude\":34.591913675377384,\"locationTime\":\"1617235359000\",\"pointflag\":false},{\"longitude\":113.72218565972796,\"latitude\":34.591910385318855,\"locationTime\":\"1617235360000\",\"pointflag\":false},{\"longitude\":113.7222740301735,\"latitude\":34.59190676321496,\"locationTime\":\"1617235361000\",\"pointflag\":false},{\"longitude\":113.72235010236945,\"latitude\":34.59189833015967,\"locationTime\":\"1617235362000\",\"pointflag\":false},{\"longitude\":113.72241220150126,\"latitude\":34.59188787565236,\"locationTime\":\"1617235363000\",\"pointflag\":false},{\"longitude\":113.72246426880851,\"latitude\":34.591877485541644,\"locationTime\":\"1617235364000\",\"pointflag\":false},{\"longitude\":113.72250778485552,\"latitude\":34.59187124023049,\"locationTime\":\"1617235365000\",\"pointflag\":false},{\"longitude\":113.7225465602701,\"latitude\":34.59187093261544,\"locationTime\":\"1617235366000\",\"pointflag\":false},{\"longitude\":113.72258381176584,\"latitude\":34.591898144461574,\"locationTime\":\"1617235368000\",\"pointflag\":false},{\"longitude\":113.72262316606361,\"latitude\":34.591919871850536,\"locationTime\":\"1617235375000\",\"pointflag\":false},{\"longitude\":113.72268875781026,\"latitude\":34.59192355612817,\"locationTime\":\"1617235377000\",\"pointflag\":false},{\"longitude\":113.72272385858278,\"latitude\":34.59192954542092,\"locationTime\":\"1617235378000\",\"pointflag\":false},{\"longitude\":113.72276057297103,\"latitude\":34.5919369631494,\"locationTime\":\"1617235379000\",\"pointflag\":false},{\"longitude\":113.72279447913303,\"latitude\":34.5919447944006,\"locationTime\":\"1617235380000\",\"pointflag\":false},{\"longitude\":113.72282888675484,\"latitude\":34.59195205670262,\"locationTime\":\"1617235381000\",\"pointflag\":false},{\"longitude\":113.7228687549676,\"latitude\":34.5919623018956,\"locationTime\":\"1617235382000\",\"pointflag\":false},{\"longitude\":113.722911665025,\"latitude\":34.591977311826305,\"locationTime\":\"1617235383000\",\"pointflag\":false},{\"longitude\":113.72295250404119,\"latitude\":34.5919952725437,\"locationTime\":\"1617235384000\",\"pointflag\":false},{\"longitude\":113.72299073385435,\"latitude\":34.59202047152477,\"locationTime\":\"1617235385000\",\"pointflag\":false},{\"longitude\":113.72302655351386,\"latitude\":34.592048089852646,\"locationTime\":\"1617235386000\",\"pointflag\":false},{\"longitude\":113.72306006069194,\"latitude\":34.59208309722275,\"locationTime\":\"1617235387000\",\"pointflag\":false},{\"longitude\":113.72309200480149,\"latitude\":34.592127332246065,\"locationTime\":\"1617235388000\",\"pointflag\":false},{\"longitude\":113.7231177775975,\"latitude\":34.59217662030795,\"locationTime\":\"1617235389000\",\"pointflag\":false},{\"longitude\":113.72314014390102,\"latitude\":34.59223291671188,\"locationTime\":\"1617235390000\",\"pointflag\":false},{\"longitude\":113.72315250558177,\"latitude\":34.592288381444455,\"locationTime\":\"1617235391000\",\"pointflag\":false},{\"longitude\":113.7231650230125,\"latitude\":34.5923487992544,\"locationTime\":\"1617235392000\",\"pointflag\":false},{\"longitude\":113.72317744879425,\"latitude\":34.59241189079759,\"locationTime\":\"1617235393000\",\"pointflag\":false},{\"longitude\":113.72319894623736,\"latitude\":34.59248441139915,\"locationTime\":\"1617235394000\",\"pointflag\":false},{\"longitude\":113.72321664687722,\"latitude\":34.59255047675969,\"locationTime\":\"1617235395000\",\"pointflag\":false},{\"longitude\":113.72322978910707,\"latitude\":34.59261218772223,\"locationTime\":\"1617235396000\",\"pointflag\":false},{\"longitude\":113.72324316577429,\"latitude\":34.59267657889712,\"locationTime\":\"1617235397000\",\"pointflag\":false},{\"longitude\":113.72325681345784,\"latitude\":34.59274250665875,\"locationTime\":\"1617235398000\",\"pointflag\":false},{\"longitude\":113.72327797517012,\"latitude\":34.592813534806425,\"locationTime\":\"1617235399000\",\"pointflag\":false},{\"longitude\":113.72330464597027,\"latitude\":34.59289110413108,\"locationTime\":\"1617235400000\",\"pointflag\":false},{\"longitude\":113.72333762274052,\"latitude\":34.59297619290449,\"locationTime\":\"1617235401000\",\"pointflag\":false},{\"longitude\":113.72337056004174,\"latitude\":34.59306203675832,\"locationTime\":\"1617235402000\",\"pointflag\":false},{\"longitude\":113.72339799320054,\"latitude\":34.59314472779332,\"locationTime\":\"1617235403000\",\"pointflag\":false},{\"longitude\":113.72341829782994,\"latitude\":34.593221135274504,\"locationTime\":\"1617235404000\",\"pointflag\":false},{\"longitude\":113.72343884457165,\"latitude\":34.59329053937438,\"locationTime\":\"1617235405000\",\"pointflag\":false},{\"longitude\":113.72346311920778,\"latitude\":34.59336209340929,\"locationTime\":\"1617235406000\",\"pointflag\":false},{\"longitude\":113.72348224207968,\"latitude\":34.593435389721876,\"locationTime\":\"1617235407000\",\"pointflag\":false},{\"longitude\":113.72349906666096,\"latitude\":34.59351037033369,\"locationTime\":\"1617235408000\",\"pointflag\":false},{\"longitude\":113.7235114061921,\"latitude\":34.59357882350845,\"locationTime\":\"1617235409000\",\"pointflag\":false},{\"longitude\":113.7235314830367,\"latitude\":34.593642607574274,\"locationTime\":\"1617235410000\",\"pointflag\":false},{\"longitude\":113.7235597977719,\"latitude\":34.59369544408532,\"locationTime\":\"1617235411000\",\"pointflag\":false},{\"longitude\":113.72359655643506,\"latitude\":34.593737890965464,\"locationTime\":\"1617235412000\",\"pointflag\":false},{\"longitude\":113.72365198336735,\"latitude\":34.59377252809106,\"locationTime\":\"1617235413000\",\"pointflag\":false},{\"longitude\":113.7237189283017,\"latitude\":34.59380202827398,\"locationTime\":\"1617235414000\",\"pointflag\":false},{\"longitude\":113.72378993761613,\"latitude\":34.5938296717561,\"locationTime\":\"1617235415000\",\"pointflag\":false},{\"longitude\":113.72387649257062,\"latitude\":34.59384418112428,\"locationTime\":\"1617235416000\",\"pointflag\":false},{\"longitude\":113.7239637662571,\"latitude\":34.593852539827346,\"locationTime\":\"1617235417000\",\"pointflag\":false},{\"longitude\":113.7240518518469,\"latitude\":34.593860913884775,\"locationTime\":\"1617235418000\",\"pointflag\":false},{\"longitude\":113.72414129183396,\"latitude\":34.593867461712975,\"locationTime\":\"1617235419000\",\"pointflag\":false},{\"longitude\":113.72423406733687,\"latitude\":34.59387345751664,\"locationTime\":\"1617235420000\",\"pointflag\":false},{\"longitude\":113.72432784695923,\"latitude\":34.593880917300545,\"locationTime\":\"1617235421000\",\"pointflag\":false},{\"longitude\":113.72441864031643,\"latitude\":34.59388889560786,\"locationTime\":\"1617235422000\",\"pointflag\":false},{\"longitude\":113.72450922780858,\"latitude\":34.59389539568308,\"locationTime\":\"1617235423000\",\"pointflag\":false},{\"longitude\":113.72460118639361,\"latitude\":34.59390498527022,\"locationTime\":\"1617235424000\",\"pointflag\":false},{\"longitude\":113.72469167821205,\"latitude\":34.59391793301156,\"locationTime\":\"1617235425000\",\"pointflag\":false},{\"longitude\":113.72477602140248,\"latitude\":34.593932736090956,\"locationTime\":\"1617235426000\",\"pointflag\":false},{\"longitude\":113.72485456046942,\"latitude\":34.5939424442857,\"locationTime\":\"1617235427000\",\"pointflag\":false},{\"longitude\":113.72492540115235,\"latitude\":34.593948404703795,\"locationTime\":\"1617235428000\",\"pointflag\":false},{\"longitude\":113.72498939699713,\"latitude\":34.59395164292691,\"locationTime\":\"1617235429000\",\"pointflag\":false},{\"longitude\":113.72504894625325,\"latitude\":34.59395290071423,\"locationTime\":\"1617235430000\",\"pointflag\":false},{\"longitude\":113.72510200329879,\"latitude\":34.5939526973414,\"locationTime\":\"1617235431000\",\"pointflag\":false},{\"longitude\":113.72515151381967,\"latitude\":34.59394894806808,\"locationTime\":\"1617235432000\",\"pointflag\":false},{\"longitude\":113.72520080574145,\"latitude\":34.5939441053221,\"locationTime\":\"1617235433000\",\"pointflag\":false},{\"longitude\":113.72525585185863,\"latitude\":34.593941932329095,\"locationTime\":\"1617235434000\",\"pointflag\":false},{\"longitude\":113.7253090378563,\"latitude\":34.59394196868194,\"locationTime\":\"1617235435000\",\"pointflag\":false},{\"longitude\":113.72535963624796,\"latitude\":34.593940441462756,\"locationTime\":\"1617235436000\",\"pointflag\":false},{\"longitude\":113.72541248964433,\"latitude\":34.59393808182159,\"locationTime\":\"1617235437000\",\"pointflag\":false},{\"longitude\":113.7254553740101,\"latitude\":34.593936743050094,\"locationTime\":\"1617235438000\",\"pointflag\":false},{\"longitude\":113.72552219876363,\"latitude\":34.59393705856652,\"locationTime\":\"1617235440000\",\"pointflag\":false},{\"longitude\":113.72556033121711,\"latitude\":34.593930431246115,\"locationTime\":\"1617235442000\",\"pointflag\":false},{\"longitude\":113.7256159329364,\"latitude\":34.593942268689624,\"locationTime\":\"1617235444000\",\"pointflag\":false},{\"longitude\":113.72565008936007,\"latitude\":34.59395276334928,\"locationTime\":\"1617235445000\",\"pointflag\":false},{\"longitude\":113.7256922816506,\"latitude\":34.59394182774805,\"locationTime\":\"1617235447000\",\"pointflag\":false},{\"longitude\":113.72570286995646,\"latitude\":34.593911276713605,\"locationTime\":\"1617235466000\",\"pointflag\":false},{\"longitude\":113.72569692324743,\"latitude\":34.593870710915766,\"locationTime\":\"1617235474000\",\"pointflag\":false},{\"longitude\":113.72570592041049,\"latitude\":34.59382093932896,\"locationTime\":\"1617235476000\",\"pointflag\":false},{\"longitude\":113.72571346013456,\"latitude\":34.5937823528569,\"locationTime\":\"1617235478000\",\"pointflag\":false},{\"longitude\":113.72570661066008,\"latitude\":34.59374916344277,\"locationTime\":\"1617235480000\",\"pointflag\":false},{\"longitude\":113.72567080977872,\"latitude\":34.59373364350527,\"locationTime\":\"1617235484000\",\"pointflag\":false}]}]}";

        //存储去过的区域
        areaList = new ArrayList<>();
        myPointList = new ArrayList<>();
        List<List<LatLng>> trackList = new ArrayList<>();
        JSONArray array = new JSONArray();

        for (int i = 0; i < trackHistoryEvents.size(); i++) {
            TrackHistoryEvent trackHistoryEvent = trackHistoryEvents.get(i);
            List<TrackHistoryEvent.PointBean> pointBeans = trackHistoryEvent.getHistoryPonits();
            List<LatLng> trackItem = new ArrayList<>();
            for (int k = 0; k < pointBeans.size(); k++) {
                TrackHistoryEvent.PointBean pointBean = pointBeans.get(k);
                double lat = pointBean.getLatitude();
                double lng = pointBean.getLongitude();
                boolean geoFenceIn = pointBean.isGeoFenceIn(); //是否在有效区域内
                String district = pointBean.getDistrict();
                String street = pointBean.getStreet();

                if (!StringUtils.isEmpty(district) && !StringUtils.isEmpty(street)) {
                    areaList.add(district + street);
                }
                String time = pointBean.getLocationTime();
                LatLng latLng = new LatLng(lat, lng);
                trackItem.add(latLng);
                myPointList.add(latLng); //为了能看到中断的全部轨迹
                if (geoFenceIn) {
                    validList.add(latLng);
                }

                //此逻辑为了上传数据
                try {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("lng", lng);
                    jsonObject.put("lat", lat);
                    jsonObject.put("updateTime", time);

                    if (pointBeans.size() == 1) { //前面的逻辑已经确定这个数组的长度最少为1  所以不用再进行为0的判断
                        jsonObject.put("pointflag", false);
                    } else if (pointBeans.size() > 1) {
                        if (i == 0) {
                            jsonObject.put("pointflag", false);
                        } else {
                            if (k == 0) {
                                jsonObject.put("pointflag", true);
                                pausePoints.add(latLng);//存放暂停点
                            } else {
                                jsonObject.put("pointflag", false);
                            }
                        }
                    }
                    array.put(jsonObject);
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
            //此数据暂时无用
            trackList.add(trackItem);
        }

        //使用完之后清空当前历史轨迹的数据
        trackHistoryEventDao.removeAll();

        //去重
        myPointList = new ArrayList<LatLng>(new LinkedHashSet<LatLng>(myPointList));
        float distance = MyUtills.getDistance(myPointList); //计算距离，根据距离动态设置轨迹移动的时间
        moveTime = MyUtills.getMoveTime(distance);


        //有效巡护去重
        List<LatLng> myValidList = new ArrayList<LatLng>(new LinkedHashSet<LatLng>(validList));
        float validMileage = MyUtills.getDistance(myValidList);
        BigDecimal b = new BigDecimal(String.valueOf(validMileage / 1000));
        //四舍五入，保留两位小数
        validDistance = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        if (myPointList.size() > 0) {
            aMap.moveCamera(CameraUpdateFactory.newLatLngBounds(getBounds(myPointList), 200));
        }

        resultCallback.result(array);

    }

    /**
     * 上报点的处理逻辑
     */
    private void uploadPointsEvent() {
        if (uploadLocationList != null) {
            if (uploadLocationList.size() > 0) {
                for (int i = 0; i < uploadLocationList.size(); i++) {
                    HashMap<String, Object> hashMap = new HashMap<>();

                    HashMap<String, Object> locationInfoMap = uploadLocationList.get(i);

                    for (String key : locationInfoMap.keySet()) {
                        LatLng latLng = (LatLng) locationInfoMap.get(key); //键是时间   值是坐标
                        double lng = latLng.longitude;
                        double lat = latLng.latitude;
                        hashMap.put("lat", lat);
                        hashMap.put("lng", lng);
                        hashMap.put("updateTime", MyUtills.stampToDateTime2(key));
                        uploadList.add(hashMap);

                        MarkerOptions markerOptions = new MarkerOptions()
                                .position(latLng)
                                .zIndex(MAP_INDEX)
                                .icon(BitmapDescriptorFactory.fromResource(com.mingtu.home.R.mipmap.icon_upload_marker));
                        Marker Marker = aMap.addMarker(markerOptions);
                        markers.add(Marker);

                        if (i == uploadLocationList.size() - 1) {
                            aMap.moveCamera(CameraUpdateFactory.changeLatLng(latLng));
                        }
                    }

                }
            }
        }
    }

    /**
     * 获取用户信息
     */
    private void getUserInfo() {

        OkGo.<String>get(Constant.getInstance().GET_USER_INFO)
                .tag(this)
                .execute(new StringDialogCallback(this) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        if (!StringUtils.isEmpty(result)) {
                            try {
                                Gson gson = GsonFactory.getSingletonGson();
                                UserInfoBean userInfoBean = new UserInfoBean();
                                userInfoBean = gson.fromJson(result, UserInfoBean.class);

                                UserInfoBean.UserBean userBean = userInfoBean.getUser();
                                String name = userBean.getName();
                                if (!StringUtils.isEmpty(name)) {

                                    if (name.length() == 1) {
                                        binding.tvName.setText(name);
                                    } else if (name.length() > 1) {
                                        binding.tvName.setText(name.substring(1, name.length()));
                                    }
                                }

                                //因为要进行401判断所以放在此处
//                                uploadTask();

                            } catch (JsonSyntaxException e) {
                                e.printStackTrace();
                            }

                        }

                    }

                    @Override
                    public void onError(Response<String> response) {
                        String result = response.body();
                        MyLogUtil.e(getClass().getSimpleName(), "onError==" + result);
                    }
                });


    }

    /**
     * 上传巡护信息
     *
     * @param
     * @return
     */
    private void uploadTask(JSONArray array) {

        String dataList = GZipUtil.compress(array.toString());

        HashMap<String, Object> hashMapOrigin = new HashMap<>();
        hashMapOrigin.put("beginTime", MyUtills.stampToDateTime2(startTime));
        hashMapOrigin.put("endTime", MyUtills.stampToDateTime2(endTime));
        hashMapOrigin.put("duration", duration);
        hashMapOrigin.put("mileage", distance);
        hashMapOrigin.put("dataList", dataList);
        hashMapOrigin.put("areaList", new LinkedHashSet(areaList));
        hashMapOrigin.put("taskPointsEntities", uploadList);
        if (validList.size() > 0) {
            hashMapOrigin.put("validMileage", validDistance);
        } else {
            hashMapOrigin.put("validMileage", 0);
        }

        String str = GsonUtils.toJson(hashMapOrigin);

        MyLogUtil.e("uploadTask", "uploadTaskStr====" + str);

        /********************断网时候的处理逻辑**********************/
        if (!netWorkState) {
            saveTrackEventData(dataList);
            return;
        }
        /******************************************/


        builder = new OkHttpClient.Builder();
        builder.addInterceptor(BaseApplication.getHttpLoggingInterceptor());
        builder.readTimeout(3 * 1000, TimeUnit.MILLISECONDS);      //读取超时时间
        builder.writeTimeout(3 * 1000, TimeUnit.MILLISECONDS);     //写入超时时间
        builder.connectTimeout(3 * 1000, TimeUnit.MILLISECONDS);   //连接超时时间

        OkGo.<String>post(Constant.getInstance().POST_UPLOAD_TASK)
                .tag(this)
                .client(builder.build())
                .retryCount(1)
                .upJson(str)
                .execute(new StringDialogCallback(this) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        MyLogUtil.e(getClass().getSimpleName(), "onSuccess==" + result);
                        if (!StringUtils.isEmpty(result)) {
                            com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(result);
                            String msg = jsonObject.getString("msg");
                            if (msg.equals(Constant.RESULT_SUCCESS)) {
                                taskId = jsonObject.getString("taskId");
                            }

                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        String result = response.body();
                        MyLogUtil.e(getClass().getSimpleName(), "onError==" + result);
                        saveTrackEventData(dataList);
                    }
                });
    }

    /**
     * 保存巡护数据
     *
     * @param dataList
     */
    private void saveTrackEventData(String dataList) {
        MyLogUtil.e("uploadTask", "TrackEvent insertEvent==== start");
        TrackEvent trackEvent = new TrackEvent();
        trackEvent.setBeginTime(MyUtills.stampToDateTime2(startTime));
        trackEvent.setEndTime(MyUtills.stampToDateTime2(endTime));
        trackEvent.setDuration(duration + "");
        trackEvent.setMileage(distance);
        trackEvent.setDataList(dataList);
        if (validList.size() > 0) {
            trackEvent.setValidMileage(validDistance);
        } else {
            trackEvent.setValidMileage(0);
        }
        trackEvent.setUpload(false);
        trackEvent.setAreaList(new ArrayList<String>(new LinkedHashSet<String>(areaList)));
        trackEvent.setTaskPointsEntities(uploadList);
        trackEventDao.insertEvent(trackEvent);
        MyLogUtil.e("uploadTask", "TrackEvent insertEvent==== end");
    }

    /**
     * 收藏
     *
     * @param
     * @return
     */

    private void collectTrack() {
        if (StringUtils.isEmpty(taskId)) {
            ToastUtils.showLong("数据获取有误！");
            return;
        }

        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("type", Constant.INTEREST_TYPE_TWO);
        hashMap.put("taskId", taskId);
        String str = GsonUtils.toJson(hashMap);
        OkGo.<String>post(Constant.getInstance().POST_FAVORITE)
                .tag(this)
                .upJson(str)
                .execute(new StringDialogCallback(this) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        if (!StringUtils.isEmpty(result)) {
                            com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(result);
                            String msg = jsonObject.getString("msg");
                            if (msg.equals(Constant.RESULT_SUCCESS)) {
                                favId = jsonObject.getString("favId");
                                ToastUtils.showLong("收藏成功！");
                            } else {
                                favId = null;
                                ToastUtils.showLong("收藏失败！");
                            }
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        String result = response.body();
                        MyLogUtil.e(getClass().getSimpleName(), "onError==" + result);

                    }
                });


    }

    /**
     * 取消收藏
     *
     * @param
     * @return
     */
    private void cancleCollectTrack() {

        if (StringUtils.isEmpty(favId)) {
            ToastUtils.showLong("请先进行收藏操作！");
            return;
        }


        OkGo.<String>post(Constant.getInstance().POST_DELETE_FAV + "/" + favId)
                .tag(this)
                .upJson("")
                .execute(new StringDialogCallback(this) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        if (!StringUtils.isEmpty(result)) {
                            com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(result);
                            String msg = jsonObject.getString("msg");
                            if (msg.equals(Constant.RESULT_SUCCESS)) {
                                ToastUtils.showLong("取消成功！");
                            } else {
                                ToastUtils.showLong("取消失败！");
                            }
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        String result = response.body();
                        MyLogUtil.e(getClass().getSimpleName(), "onError==" + result);

                    }
                });


    }

    /**
     * 显示提示信息
     */
    private void showAlertDialog(String message) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(com.mingtu.home.R.string.notifyTitle);
        builder.setMessage(message);

        builder.setNegativeButton(com.mingtu.home.R.string.cancel,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });

        builder.setPositiveButton(com.mingtu.home.R.string.sure,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });

        builder.setCancelable(false);

        builder.show();
    }


    /**
     * 组装地图截图和其他View截图，需要注意的是目前提供的方法限定为MapView与其他View在同一个ViewGroup下
     *
     * @param bitmap        地图截图回调返回的结果
     * @param viewContainer MapView和其他要截图的View所在的父容器ViewGroup
     * @param mapView       MapView控件
     * @param views         其他想要在截图中显示的控件
     */
    public static Bitmap getMapAndViewScreenShot(Bitmap bitmap, ViewGroup viewContainer, MapView mapView, View... views) {
        int width = viewContainer.getWidth();
        int height = viewContainer.getHeight();
        final Bitmap screenBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(screenBitmap);
        canvas.drawBitmap(bitmap, mapView.getLeft(), mapView.getTop(), null);
        for (View view : views) {
            view.setDrawingCacheEnabled(true);
            canvas.drawBitmap(view.getDrawingCache(), view.getLeft(), view.getTop(), null);
        }

        //先进行字节压缩，再进行质量压缩（因为ShareSDK  setImageData方法中的资源不能超过10M）

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        // 质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中
        screenBitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos);
//        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
//        return BitmapFactory.decodeStream(bais, null, null);
        byte[] bytes = baos.toByteArray();
        return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);

    }

    /**
     * 巡护区域
     */
    private void getAreaData() {
        OkGo.<String>get(MyConstant.GET_AREA)
                .tag(this)
                .execute(new MyStringDialogCallback(this) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        if (!StringUtils.isEmpty(result)) {
                            ResAreaBean resAreaBean = null;
                            try {
                                Gson gson = GsonFactory.getSingletonGson();
                                resAreaBean = new ResAreaBean();
                                resAreaBean = gson.fromJson(result, ResAreaBean.class);

                                List<ResAreaBean.FeaturesBean> featuresBeans = resAreaBean.getFeatures();
                                List<List<LatLng>> areaLatLngList = new ArrayList<>(); //存放所有区域的数据
                                List<LatLng> areaAllLatLng = new ArrayList<>();
                                for (int i = 0; i < featuresBeans.size(); i++) {
                                    ResAreaBean.FeaturesBean featuresBean = featuresBeans.get(i);
                                    ResAreaBean.FeaturesBean.PropertiesBeanX propertiesBeanX = featuresBean.getProperties();
                                    ResAreaBean.FeaturesBean.GeometryBean geometryBean = featuresBean.getGeometry();
                                    String type = geometryBean.getType();
                                    List<List<Double>> myList = null;
                                    if (type.equals("MultiPolygon")) {
                                        List<List<List<List<Double>>>> coordinates = (List<List<List<List<Double>>>>) geometryBean.getCoordinates();
                                        myList = coordinates.get(0).get(0);

                                    } else if (type.equals("Polygon")) {
                                        List<List<List<Double>>> coordinates = (List<List<List<Double>>>) geometryBean.getCoordinates();
                                        myList = coordinates.get(0);
                                    }
                                    List<DPoint> points = new ArrayList<DPoint>();  //存放地里围栏需要的数据
                                    List<LatLng> latLngs = new ArrayList<>();//存放单条区域的数据
                                    for (int j = 0; j < myList.size(); j++) {
                                        List<Double> latLngList = myList.get(j);
                                        double gpsLat = latLngList.get(1);
                                        double gpsLng = latLngList.get(0);
                                        //gps 转高德的经纬度
//                                        double[] latlngs = GPSTransToAMap.transform(gpsLat, gpsLng);
//                                        LatLng latLng = new LatLng(latlngs[0], latlngs[1]);
//                                        points.add(new DPoint(latlngs[0], latlngs[1]));

                                        LatLng latLng = new LatLng(gpsLat, gpsLng);
                                        latLngs.add(latLng); //将坐标装到数组里
                                        points.add(new DPoint(gpsLat, gpsLng));
                                        areaAllLatLng.add(latLng);

                                    }

                                    PolygonOptions polygonOptions = new PolygonOptions();
                                    polygonOptions.addAll(latLngs);
                                    polygonOptions.strokeWidth(1);
                                    polygonOptions.zIndex(45);
                                    polygonOptions.fillColor(context.getResources().getColor(R.color.bg_color_1f1e9));
                                    polygonOptions.strokeColor(context.getResources().getColor(R.color.bg_color_1f1e9));
                                    Polygon mapPolygon = aMap.addPolygon(polygonOptions);
                                    trackPolygonList.add(mapPolygon);
                                    areaLatLngList.add(latLngs);

                                    Polyline mapPolyline = aMap.addPolyline(new PolylineOptions()
                                            .addAll(latLngs)
                                            .width(8)
                                            .zIndex(100)
                                            .setDottedLine(true)
                                            .setDottedLineType(PolylineOptions.DOTTEDLINE_TYPE_SQUARE)
                                            .color(context.getResources().getColor(R.color.colorPrimary)));
                                    polylineList.add(mapPolyline);

                                }
//
//                                if (areaAllLatLng.size() > 0) {
//                                    aMap.moveCamera(CameraUpdateFactory.newLatLngBounds(getBounds(areaAllLatLng), 200));
//                                }

                            } catch (JsonSyntaxException e) {
                                e.printStackTrace();
                            }

                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        String result = response.body();
                        MyLogUtil.e(getClass().getSimpleName(), "onError==" + result);

                    }
                });
    }


}